/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-11
 * Time: 10:17
 */
public class minSub_ArrayLen {
    public static int minSubArrayLen(int target, int[] nums) {
        int sum=0;
        int ret=Integer.MAX_VALUE;
        int left=0;
        for (int right = 0; right < nums.length; right++) {
            sum+=nums[right];
            while (sum>=target){
                ret=Math.min(ret,right-left+1);
                sum-=nums[left];
                left++;
            }
        }
        return ret == Integer.MAX_VALUE ? 0 : ret;
    }

    public static void main(String[] args) {
        int[] arr=new int[]{2,3,1,2,4,3};
        System.out.println(minSubArrayLen(7,arr));
    }
}
